package md.mru.core.domains.administration;

import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;

/**
 * @author sergiu.marin
 * @since 23.04.2014.
 */
@Embeddable
public class TreeUserGroupId implements Serializable {

    private static final long serialVersionUID = -4023718664033440998L;

    /*@Column(name = "tree_id", unique = true, nullable = false, precision = 10, scale = 0)
    private long treeNodeModelId;*/
    @ManyToOne
    @JoinColumn(name = "tree_id")
    private TreeNodeModel treeNodeModel;

    @ManyToOne
    @JoinColumn(name = "group_id")
    private UserGroup userGroup;

    /*@Column(name = "user_group_id", unique = true, nullable = false, precision = 10, scale = 0)
    private long userGroupId;*/

    public TreeUserGroupId() {
        super();
    }

    public TreeUserGroupId(TreeNodeModel treeNodeModel, UserGroup userGroup) {
        this.treeNodeModel = treeNodeModel;
        this.userGroup = userGroup;
    }

    public TreeNodeModel getTreeNodeModel() {
        return treeNodeModel;
    }

    public void setTreeNodeModel(TreeNodeModel treeNodeModel) {
        this.treeNodeModel = treeNodeModel;
    }

    public UserGroup getUserGroup() {
        return userGroup;
    }

    public void setUserGroup(UserGroup userGroup) {
        this.userGroup = userGroup;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TreeUserGroupId that = (TreeUserGroupId) o;

        return !(treeNodeModel != null ? !treeNodeModel.equals(that.treeNodeModel) : that.treeNodeModel != null) && !(userGroup != null ? !userGroup.equals(that.userGroup) : that.userGroup != null);

    }

    @Override
    public int hashCode() {
        int result = treeNodeModel != null ? treeNodeModel.hashCode() : 0;
        result = 31 * result + (userGroup != null ? userGroup.hashCode() : 0);
        return result;
    }
}
